package com.woniuxy.service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service
public class EmailService {

    private final JavaMailSender mailSender;

    @Value("${spring.mail.username}")
    private String fromEmail;

    public EmailService(JavaMailSender mailSender) {
        this.mailSender = mailSender;
    }

    /**
     * 发送简单文本邮件到QQ邮箱
     * @param toQQEmail 收件人QQ邮箱（如123456@qq.com）
     * @param subject   邮件主题
     * @param text      邮件正文
     */
    public void sendToQQEmail(String toQQEmail, String subject, String text) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(fromEmail);
        message.setTo(toQQEmail);
        message.setSubject(subject);
        message.setText(text);
        mailSender.send(message);
    }
}